import { createRouter, createWebHashHistory } from "vue-router";
import type { RouteRecordRaw } from 'vue-router';
import { getEvelAndCountLevel } from '@/apis/index'
const routes: RouteRecordRaw[] = [
    {
        path: '/',
        name: 'home',
        component: () => import('../views/basic-page/index.vue')
    },
    {
        path: '/detail',
        name: 'details',
        component: () => import('../views/details/index.vue')
    },
    {
        path: '/registerAndLogin',
        name: 'registerAndLogin',
        component: () => import('../views/userRegister/index.vue')
    },
    {
        path: '/person',
        name: 'info',
        component: () => import('../views/info/index.vue')
    },
    {
        path: '/hotspot',
        name: 'my-hotspot',
        component: () => import('../views/hotspot/index.vue')
    },
    {
        path: '/message',
        name: 'my-message',
        component: () => import('../views/message/index.vue'),
    },
    //{
    //配置404页面
    //path: '/:catchAll(.*)',
    //name: '404',
    //component: () => import(''),
    //}
]


// 路由
const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// @ts-ignore
router.beforeEach(async (to, from, next) => {
    if (localStorage.getItem('t') && to.path !== '/message') {
        const { data } = await getEvelAndCountLevel();
        localStorage.setItem('l', data.level);
        localStorage.setItem('countLevel', data.countLevel);
    }
    next();
})
// 导出
export default router 